import router from "@/router";
import { Zijinyunying } from "@icon-park/vue-next";
import { useVModel } from "@vueuse/core";
import { defineComponent, ref, watch } from "vue";
import * as echarts from "echarts";
import { inject, onMounted } from "vue";

import "../assets/less/global.less";

export default defineComponent({
  props: {
    zi: Object,
  },
  emits: ["finsh"],
  setup(props: any, { emit }) {
    let echarts: any = inject("ec"); //引入

    const MyEcharts = () => {
      let myChart = echarts.init(document.getElementById("customerChart"));
      let myChart2 = echarts.init(document.getElementById("customerChart2"));
      myChart2.setOption({
        title: {
          text: "某站点用户访问来源",
          subtext: "纯属虚构",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "50%",
            data: [
              { value: 100, name: "搜索引擎" },
              { value: 735, name: "直接访问" },
              { value: 580, name: "邮件营销" },
              { value: 484, name: "联盟广告" },
              { value: 300, name: "视频广告" },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      });
      // 绘制图表
      myChart.setOption({
        title: { text: "总用户量" },
        tooltip: {},
        xAxis: {
          data: ["12-3", "12-4", "12-5", "12-6", "12-7", "12-8"],
        },
        yAxis: {},
        series: [
          {
            name: "用户量",
            type: "line",
            data: [50, 20, 36, 10, 10, 20],
          },
        ],
      });
      window.onresize = function () {
        //自适应大小
        myChart.resize();
      };
    };

    onMounted(() => {
      //需要获取到element,所以是onMounted的Hook
      MyEcharts();
    });

    const jia = () => {
      // console.log(props.zi.shu.value++);
      // alert(123);
      emit("finsh");
    };
    // const shu = useVModel(props,"value",emit);
    return () => (
      <div id="xiu">
        这里是xiu界面
        <a-button type="primary" onClick={() => jia()}>
          Primary Button
        </a-button>
        {props.zi.date.value}
        <div id="customerChart" style="width:300px;height:300px"></div>
        <div id="customerChart2" style="width:1000px;height:1000px;margin:auto"></div>
      </div>
    );
  },
});
